<template>
	<view class="beijingse mainpadding">
		<!-- 弹框 -->
		<u-picker :show="show" :title="title" :columns="columns" @confirm="confirm" @cancel="show=false"
			confirmColor="#FAB536"></u-picker>
		<u-picker :show="shows" :title="title1" keyName="name" :columns="columns1" @confirm="confirms" @cancel="shows=false"
			confirmColor="#FAB536"></u-picker>
		<view class="mainpadding ffffff radius flexbetween"  @click="show = true">
			<view class="titletext">申请类型</view>
			<view class="flexright">
				<view class="notitletext margin_right3">{{thlx?thlx:"请选择换货类型"}}</view>
				<view class="righticon"></view>
			</view>
		</view>
		<view class="mainpadding ffffff radius flexbetween margin_top" @click="shows = true">
			<view class="titletext">申请原因</view>
			<view class="flexright" >
				<view class="notitletext margin_right3">{{sqyy?sqyy:"请选择申请原因"}}</view>
				<view class="righticon"></view>
			</view>
		</view>
		<view class="mainpadding ffffff radius flexbetween margin_top">
			<view class="titletext">换货金额</view>
			<view class="qianshu ">￥{{pricedata.return_price}}</view>
		</view>
		<view class="mainpadding ffffff radius flexbetween margin_top">
			<view class="titletext">退回积分</view>
			<view class="qianshu ">￥{{pricedata.return_integral_price}}</view>
		</view>
		<view class="mainpadding ffffff radius margin_top">
			<view class="titletext">申请说明</view>
			<textarea class="textareas margin_top" placeholder="请您详细填写申请说明" v-model="sqsm" ></textarea>
		</view>
		<!-- <view class="mainpadding ffffff radius flexbetween margin_top">
			<view class="titletext">联系电话</view>
			<view class="notitletext">13768946312</view>
		</view> -->
		<!-- 固定底部 -->
		<view class="gudingdb" @click="submit">
			<view class="bigbtn">提交申请</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				shows:false,
				title:"请选择换货类型",
				title1:"请选择申请原因",
				thlx: "", //换货类型
				sqyy: "", //申请原因
				columns: [
					['我要换货(无需退货)', '退货换货']
				],
				columns1: [],
				lastmsg:{
					listid:"",//商品id
					order_id:""//订单id
				},
				pricedata:{
					return_price:"",//换货金额
					return_integral_price:""//换货积分
					
				},
				sqsm:"",
				
			}
		},
		onLoad(options) {
			this.lastmsg = JSON.parse(decodeURIComponent(options.msg));
			this.getyy()
			this.getprice()
		},
		methods: {
			getprice(){
				httpRequest.request('/api/order/getReturnPrice', 'POST', {
					order_goods_id:this.lastmsg.listid
				}, false, false, true).then(res => {
					this.pricedata = res.data
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			// 获取换货原因
			getyy() {
				httpRequest.request('/api/order/orderTklx', 'POST', {
				}, false, false, true).then(res => {
					this.columns1.push(res.data)
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			cancel() {
				this.show = false
			},
			confirm(e) {
				// console.log('confirm', e)
				this.thlx = e.value[0]
				this.show = false
			},
			confirms(e) {
				// console.log('confirm', e)
				this.sqyy = e.value[0].name
				this.shows = false
			},
			submit(){
				if(this.thlx==""){
					httpRequest.toast("请选择换货类型");
					return false
				}
				if(this.sqyy==""){
					httpRequest.toast("请选择申请原因");
					return false
				}
				if(this.sqsm==""){
					httpRequest.toast("请填写申请说明");
					return false
				}
				httpRequest.modal('提示', '确定提交申请吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/order/addApply', 'POST', {
							order_goods_id:this.lastmsg.listid,
							order_id:this.lastmsg.order_id,
							type:this.thlx=="退货换货"?1:0,
							reason:this.sqyy,
							refund_content:this.sqsm
						}, false, false, true).then(res => {
							if(res.code==1){
								setTimeout(()=>{
									uni.navigateBack(1)
								},500)
							}else{
								httpRequest.toast(res.msg);
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})	
			},
		}
	}
</script>

<style lang="scss" scoped>
	.textareas {
		width: 100%;
		box-sizing: border-box;
	}

	.qianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FAB536;
	}

	.huisetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}
</style>
